import ConvexGeometry from "./convex-geometry";
import Vec3 from "../common/vec3";
import CONSTANT from '../constant';

export default class ConvexSweepGeometry extends ConvexGeometry{
    constructor() {
        super(CONSTANT.GEOMETRY_TYPE_NULL);
    }
    init(c,_transform,_translation) {
        let translation=_translation.elements,transform=_transform.elements;
        this.c = c;
        let trX = translation[0],trY = translation[1],trZ = translation[2];
        let localTrX = transform[3] * trX + transform[6] * trY + transform[9] * trZ;
        let localTrY = transform[4] * trX + transform[7] * trY + transform[10] * trZ;
        let localTrZ = transform[5] * trX + transform[8] * trY + transform[11] * trZ;
        this.localTranslation = new Vec3();
        let v = this.localTranslation.elements;
        v[0] = localTrX;v[1] = localTrY;v[2] = localTrZ;
        this._gjkMargin = c._gjkMargin;
    }
    computeLocalSupportingVertex(_dir,_out) {
        this.c.computeLocalSupportingVertex(_dir,_out);
        let dir=_dir.elements,out=_out.elements;
        let v = this.localTranslation.elements;
        if(dir[0] * v[0] + dir[1] * v[1] + dir[2] * v[2] > 0) {
            out[0] += v[0];out[1] += v[1];out[2] += v[2];
        }
    }
}